import os

# 设置环境变量(开发配置，实际上你不应该在代码中设置环境变量，而是通过外部配置来设置)
# 详情参考文档#配置环境变量
os.environ['MYSQL_HOST'] = 'localhost'
os.environ['MYSQL_USER'] = 'root'
os.environ['MYSQL_ROOT_PASSWORD'] = '123456'

# 读取并检查环境变量是否存在
def get_env_variable(var_name):
    value = os.getenv(var_name)
    if value is None:
        raise EnvironmentError(f"环境变量缺失: '{var_name}' is not set.")
    return value

try:
    host = get_env_variable('MYSQL_HOST')
    user = get_env_variable('MYSQL_USER')
    password = get_env_variable('MYSQL_ROOT_PASSWORD')

    print(f"Host: {host}, User: {user}, Password: {password}")
except EnvironmentError as e:
    print(e)
